package com.dhcy.mqtt.controller;

import com.dhcy.mqtt.config.mqtt.MqttConfig;
import com.dhcy.mqtt.service.MqttGateway;
import com.dhcy.mqtt.util.AppResultData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/mqtt")
public class MqttController {

    @Autowired
    private MqttGateway mqttGateway;
    @Autowired
    private MqttConfig mqttConfig;

    /**
     * 向指定主题发送消息
     *
     * @param data
     * @return
     */
    @GetMapping("/sendToTopic")
    public AppResultData<String> sendToTopic(String data) {
        mqttGateway.sendToMqtt(data, mqttConfig.getTopic());
        return AppResultData.successMessage("成功");
    }


}
